package com.shujia.day14;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class HDemo1 {
    public static void main(String[] args) {
        ArrayList<Student> arrayList = new ArrayList<>();

        arrayList.add(new Student(1, "张三", 13, "男"));
        arrayList.add(new Student(2, "李四", 15, "男"));
        arrayList.add(new Student(3, "王五", 16, "女"));

        HashMap<Integer, Student> studentHashMap = new HashMap<>();


        listToMap(arrayList,studentHashMap);

        for (Map.Entry<Integer, Student> integerStudentEntry : studentHashMap.entrySet()) {
            System.out.println(integerStudentEntry.getKey()+"\t"+integerStudentEntry.getValue());
        }


    }

    public static void listToMap(ArrayList<Student> arrayList, HashMap<Integer, Student> studentHashMap){
        for (Student student : arrayList) {
            studentHashMap.put(student.id,student);
        }
    }
}

class Student implements Serializable{
//    private int sensitive = 736326;

//    long serialVersionUID = -6084813698588795818l;
    int id;
    String name;
    int age;
    transient String sex;

    public Student(int id, String name, int age, String sex) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}
